	


<script type="text/javascript">         

$(document).ready(function()
{
	var i = 0;
	var flag = false;
	
	$('#Ses1').hide();
	$('#Ses2').hide();
	$('#Ses3').hide();
	$('#explanation1').hide();
	
	$("form").submit(function() {
		
		$('.req').each(function(index)
		{
			if ($(this).val() == "") 
		    {
		      alert("Please enter all required fields ");
		      flag = true;
		      return false;
		    }
			
		});
	   
	    
	    if ($('input:[name^="Coursetitle"]').val().length > 50 ) 
	    {
	      alert("the course name is too long");
	      flag = true;
	      return false;
	    }
	    if ($('textarea:[name^="description"]').val().length > 1000 ) 
	    {
	      alert("the description  is too long");
	      flag = true;
	      return false;
	    }
	    
	    
	   $('input:[class^="num"]').each(function(index) {
		   
		   for(var k=0 ; k < $(this).val().length; ++k)
			{
	            
				var new_key1 = $(this).val()[k]; 
			    if((new_key1 < "0") || (new_key1 > "9"))
			    {
			    	alert($(this).attr("name")+" can contain only numbers");
			    	flag = true;
					return false;
					
					
			 	}
			}
		    
	   });
	   
	   

	   var startend =new Array();
	   
	   $('.Sessiontr').each(function() 
	   {
		   
		   		   $(this).children().each(function(index) 
				   {
					   startend[index] =  $(this).children().val();
					   
				   });
				   
				   if(startend[0] == "")
					{
					   return false;
					}
				   if(startend[1] == "")
					{
					   return false;
					}
				   
				   startend[0] = parseInt(startend[0]);
				   startend[1] = parseInt(startend[1]);
				   if(startend[0] > startend[1] )
					{
					   alert("a session can't end befor it start");
					   flag = true;
					   return false;
					}
				   
				   if((startend[0] < 1) || (startend[0] > 70) || (startend[1] < 1) || (startend[1] > 70) )
					{
					   alert("session's start and end can be numbers between 1-70");
					   flag = true;
					   return false;
					}
				   
				   
				   if((startend[1]- startend[0]) > 3) 
				   {
					   alert("session is a group of 1-4 consecutive time slots");
					   flag = true;
					   return false;
				   }
				   
				   var notsameday = true;
				   if(((startend[0] > 0)&&(startend[0] < 11))&&((startend[1] > 0) && (startend[1] < 11)))
				   {
					   notsameday = false;
				   }
				   if(((startend[0] > 10)&&(startend[0] < 21))&&((startend[1] > 10) && (startend[1] < 21)))
				   {
					   notsameday = false;
				   }
				   if(((startend[0] > 20)&&(startend[0] < 31))&&((startend[1] > 20) && (startend[1] < 31)))
				   {
					   notsameday = false;
				   }
				   if(((startend[0] > 30)&&(startend[0] < 41))&&((startend[1] > 30) && (startend[1] < 41)))
				   {
					   notsameday = false;
				   }
				   if(((startend[0] > 40)&&(startend[0] < 51))&&((startend[1] > 40) && (startend[1] < 51)))
				   {
					   notsameday = false;
				   }
				   if(((startend[0] > 50)&&(startend[0] < 61))&&((startend[1] > 50) && (startend[1] < 61)))
				   {
					   notsameday = false;
				   }
				   if(((startend[0] > 60)&&(startend[0] < 71))&&((startend[1] > 60) && (startend[1] < 71)))
				   {
					   notsameday = false;
				    }
				   
				   
				  if(notsameday)
					{
					   alert("a session need begin and end in the same day!");
					   flag = true;
					   return false;
					}
				   
				   
		});
	  
	   
		 if(flag == true)
		{
			 
			  alert("please fix your input");
			  flag = false;
			  return false;
			 
		}
		 i = 0;
         var queryString = $(this).serialize();        
         $("#content").load($(this).attr("action")+"?"+queryString,function(response, status, xhr) {
			  if (status == "error") {
				    var msg = "Sorry but there was an error: ";
				    $("#page").html("<br />" +"<h1>" + msg + xhr.status + " " + xhr.statusText +"</h1>" );
				  }}).fadeIn('slow');
         return false; 
         
         
	  });
	  
	
	$('#addSessions').click(function() {
		
		if(i == 0)
		{
			$('#Ses1').show();
			i++;
			return;
		}
		if(i == 1)
		{
			$('#Ses2').show();
			i++;
			return;
		}
		
		if(i == 2)
		{
			$('#Ses3').show();
			i++;
			return;
		}
		if(i > 2)
		{
			alert("For more Sessions, add manually in the add/remove Session section");
		}
		
		return;
		
	});
	$('#expSessions').click(function() {
		
		$('#explanation1').show();
		return;
		
	});
	  
  
}); 
</script>

	<h2>Add a course to the database</h2>
		<p>
		</p>
	<h3>Required information for a course</h3>

	<form action="Homeservlet" method="post">
		<table>
			<tr><td>
				<input type="hidden"  name="op" value="addcourseexe"/>
				Course title:</td>
				<td><input type="text" class="req" name="Coursetitle" size="20"/></td>
			</tr>
			<tr><td>Description</td>
				<td>
				<textarea name="description" cols="40" rows="5" class="req"></textarea>
				</td>
			</tr>
			<tr><td>Number of credit points</td>
				<td><input type="text" name="creditpoints" class="num req" size="15"/></td>
			</tr>
			<tr><td>Course capacity</td>
				<td><input type="text" name="capacity" class="num req" size="15"/></td>
			</tr>
			<tr><td>Group number</td>
				<td><input type="text" name="Group" class="num req" size="15"/></td>
			</tr>
			<tr>
				<td>Sessions: </td>
			</tr>
			<tr id="Ses0" class="Sessiontr"> 
				<td>start: <input type="text" name="start" class="num req" size="15"/></td>
				<td>end: <input type="text" name="end" class="num req" size="15"/></td>
			</tr>	
			<tr id="Ses1" class="Sessiontr">
				<td>start: <input type="text" name="start" class="num" size="15"/></td>
				<td>end: <input type="text" name="end" class="num" size="15"/></td>
			</tr>
			<tr id="Ses2" class="Sessiontr">
				<td>start: <input type="text" name="start" class="num" size="15"/></td>
				<td>end: <input type="text" name="end" class="num" size="15"/></td>
			</tr>
			<tr id="Ses3" class="Sessiontr">
				<td>start: <input type="text" name="start" class="num" size="15"/></td>
				<td>end: <input type="text" name="end" class="num" size="15"/></td>
			</tr>	
			<tr>
				<td><button type="button" id="addSessions">Add more sessions</button></td>
				<td><button type="button" id="expSessions">Explanation about session numbering</button></td>
			</tr>
		</table>
		<input type="submit" value="Add course"></input>
	</form>
	<div id="explanation1"> 
	<br />
	<p> Example : to add a session in monday from 9:00 to 12:00, you need to add start : 12 end : 14 </p>
			<table class = "usersTable">
      		<tr>
        		<th>Hour</th>
				<th>Sunday</th>
        		<th>Monday</th>
        		<th>Tuesday</th>
        		<th>Wednesday</th>
        		<th>Thursday</th>
        		<th>Friday</th>
        		<th>Saturday</th>
      		</tr>
        	<tr><td>8:00-9:00</td><td>1</td><td>11</td><td>21</td>
        	<td>31</td><td>41</td><td>51</td><td>61</td></tr>
        	<tr><td>9:00-10:00</td><td>2</td><td>12</td><td>22</td>
        	<td>32</td><td>42</td><td>52</td><td>62</td></tr>
			<tr><td>10:00-11:00</td><td>3</td><td>13</td><td>23</td>
        	<td>33</td><td>43</td><td>53</td><td>63</td></tr>
        	<tr><td>11:00-12:00</td><td>4</td><td>14</td><td>24</td>
        	<td>34</td><td>44</td><td>54</td><td>64</td></tr>
            <tr><td>12:00-13:00</td><td>5</td><td>15</td><td>25</td>
        	<td>35</td><td>45</td><td>55</td><td>65</td></tr>
        	<tr><td>13:00-14:00</td><td>6</td><td>16</td><td>26</td>
        	<td>36</td><td>46</td><td>56</td><td>66</td></tr>
			<tr><td>14:00-15:00</td><td>7</td><td>17</td><td>27</td>
        	<td>37</td><td>47</td><td>57</td><td>67</td></tr>
        	<tr><td>15:00-16:00</td><td>8</td><td>18</td><td>28</td>
        	<td>38</td><td>48</td><td>58</td><td>68</td></tr>
        	<tr><td>16:00-17:00</td><td>9</td><td>19</td><td>29</td>
        	<td>39</td><td>49</td><td>59</td><td>69</td></tr>
        	<tr><td>17:00-18:00</td><td>10</td><td>20</td><td>30</td>
        	<td>40</td><td>50</td><td>60</td><td>70</td></tr>
      	</table>
	</div>
	
